package com.antilia.infomaresme;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.model.IModel;


/**
 * @author Ernesto Reinaldo Barreiro
 *
 */
public class EnumDropDownChoice<T extends Enum<T>> extends DropDownChoice<T> {

	private static final long serialVersionUID = 1L;

	public EnumDropDownChoice(String id, Class<T> enumClass) {
		super(id);
		List<T> choices = Arrays.asList(enumClass.getEnumConstants());
		setNullValid(true);
		setChoiceRenderer(new EnumChoiceRenderer<T>(this));		
		setChoices(choices);
	}
	
	/**
	 * 
	 * @param id
	 * @param enumClass
	 * @param model
	 */
	public EnumDropDownChoice(String id, Class<T> enumClass ,IModel<T> model) {
		this(id, Arrays.asList(enumClass.getEnumConstants()), model);				
	}
	
	/**
	 * 
	 * @param id
	 * @param choices
	 * @param model
	 */
	public EnumDropDownChoice(String id, List<T> choices,IModel<T> model) {
		super(id);
		setModel(model);
		setNullValid(true);
		setChoiceRenderer(new EnumChoiceRenderer<T>(this));	
		setChoices(choices);
	}	
}
